var prefix = api + "/admin/param";

$(function () {
  var type_datas = dictByType('param_type')
  var system_datas = dictByType('dict_type');
  renderDictFilter('#systemFlag', 'dict_type')
  var addFlag = permissions.admin_syspublicparam_add
  var editFlag = permissions.admin_syspublicparam_edit
  var deleteFlag = permissions.admin_syspublicparam_del
  //没有新增权限的话删除新增按钮
  if (!addFlag) {
    $('#addBtn').remove()
  }
  var options = {
    url: prefix + "/page",
    updateUrl: "/pages/sysadm/param/paramEdit",
    removeUrl: prefix + "/{id}",
    sortName: "createTime",
    sortOrder: "desc",
    modalName: "参数",
    columns: [
      {
        title: "序号",
        formatter: function (value, row, index) {
          return $.table.serialNumber(index);
        }
      },
      {
        field: 'publicName',
        title: '参数名称',
        formatter: function (value, row, index) {
          return $.table.tooltip(value);
        }
      },
      {
        field: 'publicKey',
        title: '参数键名',
        formatter: function (value, row, index) {
          return $.table.tooltip(value);
        }
      },
      {
        field: 'publicValue',
        title: '参数键值'
      },
      {
        field: 'validateCode',
        title: '编码'
      },
      {
        field: 'systemFlag',
        title: '参数类型',
        align: 'center',
        formatter: function (value, row, index) {
          return $.table.selectDictLabel(system_datas, value);
        }
      },
      {
        field: 'status',
        title: '参数状态',
        align: 'center',
        formatter: function (value, row, index) {
          // return statusTools(row);
          return value == 0 ? "正常" : "无效"
        }
      },
      {
        field: 'publicType',
        title: '参数小类',
        align: 'center',
        formatter: function (value, row, index) {
          return $.table.selectDictLabel(type_datas, value);
        }
      },
      // {
      // 	field : 'createTime',
      // 	title : '创建时间'
      // },
      {
        title: '操作',
        align: 'center',
        formatter: function (value, row, index) {
          var actions = [];
          if (row.systemFlag != 1 && editFlag) {
            actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="$.operate.edit(\'' + row.publicId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
          }
          if (row.systemFlag != 1 && deleteFlag) {
            actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.publicId + '\')"><i class="fa fa-remove"></i>删除</a>');
          }
          return actions.join('');
        }
      }]
  };
  $.table.init(options);
});

// function statusTools(row) {
// 	if (row.status == 9) {
// 		return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\''
// 				+ row.publicId + '\')"></i> ';
// 	} else {
// 		return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\''
// 				+ row.publicId + '\')"></i> ';
// 	}
// }   

// function disable(publicId) {
// 	$.modal.confirm("确认要停用参数吗？", function() {
// 		$.operate.post(prefix + "/changeStatus", {
// 			"publicId" : publicId,
// 			"status" : 9
// 		});
// 	})
// }

// function enable(publicId) {
// 	$.modal.confirm("确认要启用参数吗？", function() {
// 		$.operate.post(prefix + "/changeStatus", {
// 			"publicId" : publicId,
// 			"status" : 0
// 		});
// 	})
// }